package ch.yiyangerp.action.login;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import ch.yiyangerp.action.IAction;
import ch.yiyangerp.service.login.UserLoginService;
import ch.yiyangerp.service.login.impl.UserLoginServiceImpl;

/**
 * 登录控制的拦截器
 * @author grc
 * @date 2015-12-13 18:52:53
 */
@SuppressWarnings("serial")
public class LoginInterceptor extends AbstractInterceptor implements IAction{


	// 没有Spring 依赖注入
	private UserLoginService userLoginService = new UserLoginServiceImpl();

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		// TODO Auto-generated method stub
		
		// 获取请求相关的ActionContext实例
		ActionContext ctx = invocation.getInvocationContext();
		Map session = ctx.getSession();
		// 获取session里的userName
		String userName = (String) session.get("userName");
		
		if(userName != null && userLoginService.loginInterceptorSearch(userName))
		{
			return invocation.invoke();
		}
		else
		{
			return IAction.NOLOGIN;
		}
	}
	
	
	public UserLoginService getUserLoginService() {
		return userLoginService;
	}

	public void setUserLoginService(UserLoginService userLoginService) {
		this.userLoginService = userLoginService;
	}


}
